package ooo.reindeer.cedf.components;

import ooo.reindeer.commons.Property;
import ooo.reindeer.logging.ILogger;
import ooo.reindeer.logging.LogUtil;

public class DefaultComponentsLoader implements IComponentsLoader {

    private static final ILogger logger = LogUtil.getLogger(DefaultComponentsLoader.class);

    public <T extends IComponent> T newInstance(String id,String calssName, Property config) {



        try {

            logger.debug("newInstance:id=[{}]	calssName=[{}]	config=[{}]", id, calssName, config);
            Class clazz = Class.forName(calssName);
            IComponent component = (T) clazz.newInstance();

            component.init(id,config);
            return (T) component;
        } catch (Exception e) {
            logger.error("newInstance() exception = [{}] with: id = [{}], calssName = [{}], config = [{}]",e.getMessage() , id,  calssName,  config);

            throw new RuntimeException(e);
        }
    }

}
